//
//  XXTea.h
//  homelib
//
//  Created by liutu on 12-2-19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#ifndef XXTea_h
#define XXTea_h

#include <stddef.h> /* for size_t & NULL declarations */

typedef unsigned long  uint32;
typedef unsigned char  unchar;
typedef unsigned short uint16;

#if defined(_MSC_VER)

typedef unsigned __int32 xxtea_long;

#else

#if defined(__FreeBSD__) && __FreeBSD__ < 5
/* FreeBSD 4 doesn't have stdint.h file */
#include <inttypes.h>
#else
#include <stdint.h>
#endif

//typedef uint32_t xxtea_long;
typedef unsigned long xxtea_long;

#endif /* end of if defined(_MSC_VER) */



#define XXTEA_MX (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z)
#define XXTEA_DELTA 0x9e3779b9

void xxtea_long_encrypt(xxtea_long *v, xxtea_long len, xxtea_long *k);
void xxtea_long_decrypt(xxtea_long *v, xxtea_long len, xxtea_long *k);

uint32 xxtea_byte4_encrypt(unchar *pByte4,uint32 *key);
void xxtea_buf_encrypt(unchar *buf,uint32 bytcnt,uint32 *key);

uint32 xxtea_byte4_decrypt(unchar *pByte4,uint32 *key);
void xxtea_buf_decrypt(unchar *buf,uint32 bytcnt,uint32 *key);

uint32 unpackorder(unchar *pByte4,uint16 len);

uint32 byte4_to_uint32(unchar *pByte4);
void uint32_to_byte4(uint32 num,unchar *pByte4);
#endif
